//
//  VC2.swift
//  ObjcCodable
//
//  Created by chenbo on 2025/2/10.
//

import UIKit

class VC2: UIViewController {
    
    var contentLabel = UILabel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        title = NSStringFromClass(Self.self)
        contentLabel.numberOfLines = 0
        view.addSubview(contentLabel)
        contentLabel.translatesAutoresizingMaskIntoConstraints = false
        contentLabel.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
        contentLabel.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
        contentLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        
        guard let resp = DataSourceTool.readLocalFile(withName: "gifts") as? [String: Any] else {
            return
        }
        guard let respInfo = GiftsResp.instance(jsonObject: resp) else {
            return
        }
        print(respInfo)
        guard let jsonString = respInfo.jsonString else {
            return
        }
        print(jsonString)
        guard let resp2 = GiftsResp.instance(jsonString: jsonString) else {
            return
        }
        print(resp2)
        self.contentLabel.text = resp2.description + "\ndata.list:\n" + (resp2.data?.list?.description ?? "")
        guard let list = resp2.data?.list else {
            return
        }
        print("list is:",list)
        guard let res3 = JSONEncodableUtil.jsonObject(list) else {
            return
        }
        print("res3is: ", res3)
        guard let jsonDict = respInfo.jsonObject else {
            return
        }
        print(jsonDict)
        
        guard let resp2 = DataSourceTool.readLocalFile(withName: "list") as? [Any] else {
            return
        }
        let arr2 = [List].instance(jsonObject: resp2)
        debugPrint("arr2: \(arr2 ?? [])")
    }
}
